package com.example.demo.Mapper;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.Student;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;


import java.util.List;

@SpringBootTest
public class Mybatis_plus_test {

    @Autowired
    private StudentMapper studentMapper;

    @Test
    public void testselect(){
        List<Student> students = studentMapper.selectList(null);
        students.forEach(System.out::println);
    }

    @Test
    public void testinsert(){

        Student student = new Student();
        student.setSid("11");
        student.setAcademy("艺术学院");
        student.setSex("男");
        student.setName("李白");
        studentMapper.insert(student);
    }
    @Test
    public void testupdate(){
        Student student = new Student();
        student.setSid("11");
        student.setTel("13972442365");
        student.setDid(416);
        studentMapper.updateById(student);
    }

    @Test
    public void test4(){
        QueryWrapper<Student> wrapper=new QueryWrapper<>();
        wrapper
                .isNotNull("grade")
                .eq("did",416);

        studentMapper.selectList(wrapper).forEach(System.out::println);

    }

    @Test
    public void test5(){
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        wrapper
                .between("grade",60,80);
        studentMapper.selectList(wrapper).forEach(System.out::println);
        System.out.println(studentMapper.selectCount(wrapper));
    }

    @Test
    public void test6(){
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        wrapper
                .likeRight("tel","139");
        studentMapper.selectList(wrapper).forEach(System.out::println);

    }
}
